//
//  VisitDocCell.m
//  Doctor
//
//  Created by 阳光 on 16/9/6.
//  Copyright © 2016年 阳光. All rights reserved.
//

#import "VisitDocCell.h"
#import "AddDocAdviceVC.h"

@interface VisitDocCell ()

@property(nonatomic,strong)UIView *bgView;

// 姓名中文
@property(nonatomic,strong)UILabel *cnameLabel;

// 姓名英文
@property(nonatomic,strong)UILabel *enameLabel;

@property(nonatomic,strong)UIView *sexLine;

// 性别
@property(nonatomic,strong)UILabel *sexLabel;

@property(nonatomic,strong)UIView *ageLine;

// 年龄
@property(nonatomic,strong)UILabel *ageLabel;

@property(nonatomic,strong)UIView *midLine;

//@property(nonatomic,strong)CustomButton *addDoctorAdviceBtn;
@property(nonatomic,strong)UIButton *addDoctorAdviceBtn;

@end

@implementation VisitDocCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor=MAIN_BACK_COLOR;
        self.cnameLabel.font=Font_Number(16);
        self.enameLabel.font=Font_Number(16);
        self.sexLabel.font=Font_Number(16);
        self.ageLabel.font=Font_Number(16);
       
        self.midLine.hidden=NO;
        self.sexLine.hidden=NO;
        self.ageLine.hidden=NO;
        
        self.addDoctorAdviceBtn.hidden=NO;
        
    };
    return self;
}

-(UIView *)bgView
{
    if (_bgView==nil) {
        _bgView=[UIView new];
        [self.contentView addSubview:_bgView];
        [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_equalTo(kmargin);
            make.right.bottom.mas_equalTo(-kmargin);
        }];
        _bgView.backgroundColor=WhiteColor;
    }
    return _bgView;
}

// cnameLabel
-(UILabel *)cnameLabel
{
    if (!_cnameLabel) {
        _cnameLabel=[self getLabelWithText:@"张三" font:Font_Number(16) textColor:Color333333 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.bgView addSubview:_cnameLabel];
        [_cnameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.mas_equalTo(kmargin);
            make.right.mas_equalTo(self.enameLabel.mas_left).offset(-kmargin);
        }];
    }
    return _cnameLabel;
}

// enameLabel
-(UILabel *)enameLabel
{
    if (!_enameLabel) {
        _enameLabel=[self getLabelWithText:@"zhangsan" font:Font_Number(16) textColor:Color666666 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.bgView addSubview:_enameLabel];
        [_enameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.cnameLabel.mas_right).offset(kmargin);
            make.centerY.mas_equalTo(self.cnameLabel.mas_centerY);
        }];
    }
    return _enameLabel;
}

-(UIView *)ageLine
{
    if (_ageLine==nil) {
        _ageLine=[UIView new];
        [self.bgView addSubview:_ageLine];
        [_ageLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.ageLabel.mas_left).offset(-kmargin);
            make.top.mas_equalTo(self.bgView.mas_top).offset(kmargin);
            make.bottom.mas_equalTo(self.midLine.mas_top).offset(-kmargin);
            make.width.mas_equalTo(1);
        }];
        _ageLine.backgroundColor=ColorE5E5E5;
    }
    return _ageLine;
}

// ageLabel
-(UILabel *)ageLabel
{
    if (!_ageLabel) {
        _ageLabel=[self getLabelWithText:@"24岁" font:Font_Number(16) textColor:Color333333 textAlignment:NSTextAlignmentRight lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.bgView addSubview:_ageLabel];
        [_ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-kmargin);
            make.centerY.mas_equalTo(self.cnameLabel.mas_centerY);
            make.left.mas_equalTo(self.ageLine.mas_right).offset(kmargin);
        }];
    }
    return _ageLabel;
}

-(UIView *)sexLine
{
    if (_sexLine==nil) {
        _sexLine=[UIView new];
        [self.bgView addSubview:_sexLine];
        [_sexLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.sexLabel.mas_left).offset(-kmargin);
            make.top.mas_equalTo(self.bgView.mas_top).offset(kmargin);
            make.bottom.mas_equalTo(self.midLine.mas_top).offset(-kmargin);
            make.width.mas_equalTo(1);
        }];
        _sexLine.backgroundColor=ColorE5E5E5;
    }
    return _sexLine;
}

// sexLabel
-(UILabel *)sexLabel
{
    if (!_sexLabel) {
        _sexLabel=[self getLabelWithText:@"女" font:Font_Number(16) textColor:Color333333 textAlignment:NSTextAlignmentRight lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.bgView addSubview:_sexLabel];
        [_sexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.ageLine.mas_left).offset(-kmargin);
            make.centerY.mas_equalTo(self.cnameLabel.mas_centerY);
            make.left.mas_equalTo(self.sexLine.mas_right).offset(kmargin);
        }];
    }
    return _sexLabel;
}

-(UIView *)midLine
{
    if (_midLine==nil) {
        _midLine=[UIView new];
        [self.bgView addSubview:_midLine];
        [_midLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.bgView.mas_left);
            make.right.mas_equalTo(self.bgView.mas_right);
            make.bottom.mas_equalTo(self.cnameLabel.mas_bottom).offset(kmargin);
            make.height.mas_equalTo(1);
        }];
        _midLine.backgroundColor=ColorE5E5E5;
    }
    return _midLine;
}

-(UIButton *)addDoctorAdviceBtn
{
    if (!_addDoctorAdviceBtn) {
        _addDoctorAdviceBtn=[UIButton buttonWithType:UIButtonTypeCustom];
//        _addDoctorAdviceBtn.titleLabel.font=Font_Number(14);
//        [_addDoctorAdviceBtn setTitleColor:Color000000 forState:0];
//        [_addDoctorAdviceBtn setTitle:@"添加医嘱" forState:0];
//        [_addDoctorAdviceBtn setImageEdgeInsets:UIEdgeInsetsMake(0,-kmargin,kmargin/2,0)];
//        [_addDoctorAdviceBtn setImage:[UIImage imageNamed:@"addIcon"] forState:0];
////        _addDoctorAdviceBtn.status=FLAlignmentStatusLeft;
        [_addDoctorAdviceBtn addTarget:self action:@selector(addDoctorAdviceBtnEvent) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:_addDoctorAdviceBtn];
        [_addDoctorAdviceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(100);
            make.left.mas_equalTo((APPW-100)/2);
            make.bottom.mas_equalTo(-kmargin);
            make.top.mas_equalTo(self.midLine.mas_bottom).offset(kmargin);
        }];
        
        
        UIImageView *addIcon=[UIImageView new];
        [_addDoctorAdviceBtn addSubview:addIcon];
        [addIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin/2);
            make.centerY.mas_equalTo(self.addDoctorAdviceBtn.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(kmargin*3/2,kmargin*3/2));
        }];
        addIcon.image=[UIImage imageNamed:@"add"];
        
        UILabel *addLabel=[_addDoctorAdviceBtn getLabelWithText:NSLocalizedString(@"Add advice", nil) font:Font_Number(16) textColor:Color333333 textAlignment:NSTextAlignmentRight lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];//@"添加医嘱"
        [_addDoctorAdviceBtn addSubview:addLabel];
        [addLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(addIcon.mas_right).offset(kmargin/2);
            make.centerY.mas_equalTo(self.addDoctorAdviceBtn.mas_centerY);
        }];
    }
    return _addDoctorAdviceBtn;
}


-(void)addDoctorAdviceBtnEvent
{
    NSLog(@"你点击哪了？");
//    VisitPatientInfoVC *visitPatientInfoVC=[VisitPatientInfoVC new];
//    VisitDocListModel *visitDocListModel=self.visitDocArr[indexPath.row];
//    visitPatientInfoVC.visitDocListModel=self.visitDocArr[indexPath.row];
//    visitPatientInfoVC.patientID=visitDocListModel.ID;
//    [self.navigationController pushViewController:visitPatientInfoVC animated:NO];
    // 跳转到添加医生医嘱界面
    AddDocAdviceVC *addDocAdviceVC=[AddDocAdviceVC new];
    addDocAdviceVC.patientID=_visitDocListModel.ID;
    addDocAdviceVC.visitDocListModel=_visitDocListModel;
    UIViewController *next=(UIViewController *)[self getCurrentViewController];
    [next.navigationController pushViewController:addDocAdviceVC animated:NO];
    

}

-(void)setVisitDocListModel:(VisitDocListModel *)visitDocListModel
{
    _visitDocListModel=visitDocListModel;
    
    _cnameLabel.text=visitDocListModel.name;
    _enameLabel.text=visitDocListModel.en_name;
    
    if ([visitDocListModel.garden isEqualToString:@"1"])
    {
        _sexLabel.text= NSLocalizedString(@"Male", nil);//@"男";
    }
    else
    {
        _sexLabel.text = NSLocalizedString(@"Female", nil);//@"女";
    }
    
    _ageLabel.text=visitDocListModel.years;
   
}

@end
